<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增题目</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css">
</head>
<body>
<div style="padding: 15px;">
    <form class="bs-example bs-example-form">
        <table class="table">
            <tr>
                <td width="100">题目ID：</td>
                <td width="450">
                    <input type="text" class="form-control" name="sid" placeholder="请输入题目ID" onchange='SidValid(this)'>
                    <input type="hidden" class="form-control" name="seid" value=''>
                </td>
            </tr>
            <tr>
                <td>排序：</td>
                <td><input type="text" class="form-control" name="sorder" placeholder="请输入序列号"></td>
            </tr>
        </table>
        <button class="btn btn-primary btn-lg btn-block" type='button' onclick='AddInfo()'>提交保存</button>
    </form>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script>
    function SidValid(obj) {
        var Sid = $(obj).val(),
            Seid = $(obj).next().val(),
            empty = '',
            data;
        if (Sid) {
            data = {seid:Seid};
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: "/subjectBySeid",
                data: data,
                success: function (json) {
                    for (var i=0;i<json.data.length;i++){
                        if (Sid==json.data[i].id){
                            layer.msg('该题目已在套题中', {icon: 2, time: 2000});
                            $(obj).val(empty);
                        }
                    }
                },
            });
        }
    }

    function AddInfo() {
        var sid = $('input[name=sid]').val(),
            seid = $('input[name=seid]').val(),
            sorder = $('input[name=sorder]').val();
        if (!seid) {
            layer.msg('参数错误', {icon: 2, time: 1000});
            setTimeout(function () {
                parent.location.reload();
            }, 1000);
            return false;
        }
        if (!sid) {
            layer.msg('请输入题目ID', {icon: 2, time: 1000});
            $('input[name=sid]').focus();
            return false;
        }
        if (!sorder) {
            layer.msg('请输入序列号', {icon: 2, time: 1000});
            $('input[name=sorder]').focus();
            return false;
        }
        /*var arr = [];
        var data = new Object();
        data.seid = seid;
        data.sid=sid;
        data.sorder=sorder;
        arr.push(data);*/
        var arr = [];
        arr.push({seid:seid,sid:sid,sorder:sorder});
        console.info(JSON.stringify(arr))
        $.ajax({
            type: 'POST',
            contentType: 'application/json;charset=UTF-8',
            dataType: 'json',
            url: "/secondType/relateSub",
            data:JSON.stringify(arr).trim(),
            success: function (json) {
                if (json.status == "success") {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff']
                    });
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                } else {
                    layer.msg(json.msg, {icon: 2, time: 1000});
                }
            },
            error: function () {
                layer.msg('网络连接失败', {icon: 5, area: ['', '15%'], time: 1000});
            }
        });

    }
</script>
</body>
</html>